package org.zxp.designpattern.builder;

/**
 * @program: effectiveJava
 * @description: 自己实现的builder
 * @author: X-Pacific zhang
 * @create: 2019-08-22 15:03
 **/
public class Pojo2 {
    private String name;
    private int age;
    private String sex;
    private String phone;

    @Override
    public String toString() {
        return "Pojo2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }

    private Pojo2(Builder builder){
        name = builder.name;
        age = builder.age;
        sex = builder.sex;
        phone = builder.phone;
    }

    public static Builder builder(){
        return new Builder();
    }

    public static class Builder{
        private String name;
        private int age;
        private String sex;
        private String phone;

        public Pojo2 build(){
            return new Pojo2(this);
        }

        public Builder name(String name){
            this.name = name;
            return this;
        }

        public Builder sex(String sex){
            this.sex = sex;
            return this;
        }

        public Builder phone(String phone){
            this.phone = phone;
            return this;
        }

        public Builder age(int age){
            this.age = age;
            return this;
        }
    }
}


class Test2{
    public static void main(String[] args){
        Pojo2 pojo2 = Pojo2.builder().age(1).name("zxp").sex("男").phone("111").build();
        System.out.println(pojo2);
    }
}
